import { request } from '@umijs/max';

// 登录方式枚举
export enum LoginType {
  PASSWORD = 'PASSWORD',  // 密码登录
  CODE = 'CODE'  // 验证码登录
}

// 登录请求参数
export interface LoginRequest {
  email: string;
  password?: string;
  code?: string;
  loginType: LoginType;
}

// 注册请求参数
export interface RegisterRequest {
  email: string;
  password: string;
  code: string;
}

// 用户信息接口
export interface UserInfo {
  id: number;
  email: string;
  nickname?: string;
  avatar?: string;
  token: string;
}

// API接口
export async function login(data: LoginRequest) {
  return request<UserInfo>('/auth/login', {
    method: 'POST',
    data,
  });
}

export async function register(data: RegisterRequest) {
  return request<UserInfo>('/auth/register', {
    method: 'POST',
    data,
  });
}

export async function sendVerificationCode(email: string, type: 'LOGIN' | 'REGISTER') {
  return request('/auth/send-code', {
    method: 'POST',
    data: { email, type },
  });
} 